package cn.wp.common.core.generate;

import cn.wp.common.core.generate.meta.Author;
import cn.wp.common.core.generate.meta.Table;
import cn.wp.common.core.generate.meta.TableColumn;
import org.thymeleaf.context.Context;

import java.util.List;

/**
 * 所有层代码生成类
 * Created by chenyb on 2019/10/22
 */
public class GenerateAllTemplate extends GenerateCode {

    @Override
    public String tpl(){
        return null;
    }

    @Override
    public String create(String tpl, Table table, Author author, List<TableColumn> tableColumnList) {
        StringBuilder stringBuilder = new StringBuilder();
        GenerateCode generateDoTemplate = new GenerateDoTemplate();
        GenerateCode generateDtoTemplate = new GenerateDtoTemplate();
        GenerateCode generateDaoTemplate = new GenerateDaoTemplate();
        GenerateCode generateServiceTemplate = new GenerateServiceTemplate();
        GenerateCode generateControllerTemplate = new GenerateControllerTemplate();

        Context ctx = new Context();
        ctx.setVariable("columnList",tableColumnList);
        ctx.setVariable("table",table);
        ctx.setVariable("author",author);

        stringBuilder.append("--------------------------Do----------------------------------\n");
        stringBuilder.append(templateEngine.process(generateDoTemplate.tpl(),ctx));

        stringBuilder.append("--------------------------Dto----------------------------------\n");
        stringBuilder.append(templateEngine.process(generateDtoTemplate.tpl(),ctx));

        stringBuilder.append("--------------------------Dao----------------------------------\n");
        stringBuilder.append(templateEngine.process(generateDaoTemplate.tpl(),ctx));

        stringBuilder.append("--------------------------Service----------------------------------\n");
        stringBuilder.append(templateEngine.process(generateServiceTemplate.tpl(),ctx));

        stringBuilder.append("--------------------------Controller----------------------------------\n");
        stringBuilder.append(templateEngine.process(generateControllerTemplate.tpl(),ctx));

        return stringBuilder.toString();
    }

}
